package com.flink.hbase;

import java.io.Serializable;
import java.util.Objects;

/**
 * 丰富化的用户数据模型
 * 包含原始用户信息和关联的维度信息
 */
public class EnrichedUser implements Serializable {
    
    // 原始用户数据
    private String userId;
    private String name;
    private Integer age;
    private String gender;
    private Long ts;
    private String dt;
    
    // 维度丰富化字段
    private String userCategory;
    private String userLevel;
    private String regionInfo;
    private Boolean isVip;
    private Long enrichmentTime;

    public EnrichedUser() {
    }

    public EnrichedUser(User user) {
        this.userId = user.getUserId();
        this.name = user.getName();
        this.age = user.getAge();
        this.gender = user.getGender();
        this.ts = user.getTs();
        this.dt = user.getDt();
        this.enrichmentTime = System.currentTimeMillis();
    }

    // Getters and Setters
    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public Long getTs() {
        return ts;
    }

    public void setTs(Long ts) {
        this.ts = ts;
    }

    public String getDt() {
        return dt;
    }

    public void setDt(String dt) {
        this.dt = dt;
    }

    public String getUserCategory() {
        return userCategory;
    }

    public void setUserCategory(String userCategory) {
        this.userCategory = userCategory;
    }

    public String getUserLevel() {
        return userLevel;
    }

    public void setUserLevel(String userLevel) {
        this.userLevel = userLevel;
    }

    public String getRegionInfo() {
        return regionInfo;
    }

    public void setRegionInfo(String regionInfo) {
        this.regionInfo = regionInfo;
    }

    public Boolean getIsVip() {
        return isVip;
    }

    public void setIsVip(Boolean isVip) {
        this.isVip = isVip;
    }

    public Long getEnrichmentTime() {
        return enrichmentTime;
    }

    public void setEnrichmentTime(Long enrichmentTime) {
        this.enrichmentTime = enrichmentTime;
    }

    /**
     * 使用维度数据丰富用户信息
     */
    public void enrichWithDimension(DimensionData dimensionData) {
        if (dimensionData == null || !dimensionData.getIsActive()) {
            return;
        }

        switch (dimensionData.getCategory()) {
            case "user_category":
                this.userCategory = dimensionData.getDimensionValue();
                break;
            case "user_level":
                this.userLevel = dimensionData.getDimensionValue();
                break;
            case "region":
                this.regionInfo = dimensionData.getDimensionValue();
                break;
            case "vip_status":
                this.isVip = "true".equalsIgnoreCase(dimensionData.getDimensionValue());
                break;
        }
        
        this.enrichmentTime = System.currentTimeMillis();
    }

    /**
     * 检查是否完全丰富化
     */
    public boolean isFullyEnriched() {
        return userCategory != null && userLevel != null && regionInfo != null && isVip != null;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        EnrichedUser that = (EnrichedUser) o;
        return Objects.equals(userId, that.userId) &&
               Objects.equals(name, that.name) &&
               Objects.equals(age, that.age) &&
               Objects.equals(gender, that.gender) &&
               Objects.equals(ts, that.ts) &&
               Objects.equals(dt, that.dt) &&
               Objects.equals(userCategory, that.userCategory) &&
               Objects.equals(userLevel, that.userLevel) &&
               Objects.equals(regionInfo, that.regionInfo) &&
               Objects.equals(isVip, that.isVip);
    }

    @Override
    public int hashCode() {
        return Objects.hash(userId, name, age, gender, ts, dt, userCategory, userLevel, regionInfo, isVip);
    }

    @Override
    public String toString() {
        return "EnrichedUser{" +
               "userId='" + userId + '\'' +
               ", name='" + name + '\'' +
               ", age=" + age +
               ", gender='" + gender + '\'' +
               ", ts=" + ts +
               ", dt='" + dt + '\'' +
               ", userCategory='" + userCategory + '\'' +
               ", userLevel='" + userLevel + '\'' +
               ", regionInfo='" + regionInfo + '\'' +
               ", isVip=" + isVip +
               ", enrichmentTime=" + enrichmentTime +
               '}';
    }
} 